import { defineStore } from 'pinia'
import { useUserStore } from './user.js'
import { homeMenus,walletMenus ,myMenus} from '@/common/data/localData.js'
export const useChannelStore = defineStore('channelStoreId', {
	state() {
		return {
			
		}
	},
	actions: {
		//更新机构类型
		updateChannelType(type) {
			const userStore = useUserStore()
			userStore.user.paymentChannel = type
			this.updateTabBarStyle()
		},
		//更新底部TabBar
		updateTabBarStyle() {
			let color = '#5F56EF'
			if(this.channelType == 'QB'){
				color = '#4CBBF5'
			}
			else if(this.channelType == 'HHB'){
				color = '#EC6B63'
			}
			uni.setTabBarStyle({
				selectedColor: color
			})
			const tabbarSelectIcons = ['/static/tabbar/tab_icon_p1','/static/tabbar/tab_icon_p2','/static/tabbar/tab_icon_p3','/static/tabbar/tab_icon_p4']
			tabbarSelectIcons.forEach((item,index)=>{
				uni.setTabBarItem({
					index,
					selectedIconPath:`${item}_${this.channelType}@2x.png`
				})
			})
		},
	},
	getters: {
		//当前选择的机构类型 QB：钱包 KDB：开店宝 HHB：合汇宝
		channelType() {
			const userStore = useUserStore()
			return userStore.user.paymentChannel || 'KDB'
		},
		//首页菜单
		homeMenuList() {
			return homeMenus.map((item) => {
				return {
					title: item.title,
					type: item.type,
					icon: (item.type == 2 || item.type == 3 || item.type == 4 || item.type == 6) ? `${item.icon}_${this.channelType}@2x.png` : `${item.icon}@2x.png`
				}
			})
		},
		//钱包菜单
		walletMenuList() {
			return walletMenus.map((item) => {
				return {
					title: item.title,
					type: item.type,
					icon: `${item.icon}_${this.channelType}@2x.png`
				}
			})
		},
		//我的菜单
		myMenuList() {
			const userStore = useUserStore()
			let myMenuList = []
			myMenus.forEach(item=>{
				if(item.type != 1){
					myMenuList.push(item)
				}
				else{
					if(userStore.user.agentType == '02'){
						myMenuList.push(item)
					}
				}
			})
			return myMenuList.map((item) => {
				return {
					title: item.title,
					type: item.type,
					icon: `${item.icon}_${this.channelType}@2x.png`
				}
			})
		},
		// 首页顶部大背景图类名
		homeBigBgClassName() {
			return `top-bg-${this.channelType}`
		},
		// 我的顶部大背景图类名
		myBigBgClassName() {
			return `my-top-bg-${this.channelType}`
		},
		//机构红色系logo
		channelTypeRedIcon(){
			return `/static/home/channel_icon_${this.channelType}${this.channelType == 'HHB' ? '_red' : ''}@2x.png`
		},
		//机构白色系logo
		channelTypeWhiteIcon(){
			return `/static/home/channel_icon_${this.channelType}${this.channelType == 'HHB' ? '_white' : ''}@2x.png`
		},
		// 首页顶部小背景图类名
		homeSmallBgClassName() {
			return `money-info-bg-${this.channelType}`
		}
	},
	//开启数据持久化
	persist: true
})